package StudyCode.summary.zipfile;

import java.io.*;
import java.util.zip.GZIPInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GunzipObject {
	public static Serializable gunzipObject(byte[] bytes)
			throws IOException, ClassNotFoundException {

		ByteArrayInputStream baIn = null;
		GZIPInputStream gzIn = null;
		ObjectInputStream objIn = null;
		try {
			baIn = new ByteArrayInputStream(bytes);
			gzIn = new GZIPInputStream(baIn);
			objIn = new ObjectInputStream(gzIn);
			return (Serializable) objIn.readObject();
		} finally {
			closeQuietly(objIn);
			closeQuietly(gzIn);
			closeQuietly(baIn);
		}

	}

	public static void closeQuietly(Closeable stream) {
		if (stream != null) {
			try {
				stream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
